from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from unittest import runner

# 打开浏览器
driver = webdriver.Chrome()
# 访问的网页
driver.get('http://192.168.1.25/crm')
driver.implicitly_wait(30)
# 最大化窗口
driver.maximize_window()

username = '杨应科'
password = '123456'

# 定位器
username_locator = (By.NAME,'name')
password_locator = (By.NAME,'password')
dl_locator= (By.NAME,'submit')
jiarenwu_locator = (By.CSS_SELECTOR,'#calendar > div.c-event-grid > div.c-task-body > div.data-head > a')
zhuti_locator = (By.ID,'subject')
baocun_locator = (By.CSS_SELECTOR,'body > div.container > div.row-fluid > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)')
fzr_locator = (By.ID,'owner_name')
xzfzr_locator = (By.CSS_SELECTOR,'#ta2 > input')
dianjiok_locator = (By.XPATH,'/html/body/div[7]/div[3]/div/button[1]')
# xiangguanren = (By.NAME,'about_roles_name')
# quanbuxuanhe = (By.CSS_SELECTOR,'#ta2 > input')
# dianji_ok1 = (By.CSS_SELECTOR,'body > div:nth-child(14) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1)')
xzxg_locator = (By.CSS_SELECTOR,'#select1')
xzlxr_locator = (By.CSS_SELECTOR,'#select1 > option:nth-child(2)')
srnr_locator = (By.CSS_SELECTOR,'#module_name')
gx_locator = (By.CSS_SELECTOR,'#data2 > tr > td:nth-child(1) > input[type=radio]')
dianji_locator= (By.XPATH,'/html/body/div[9]/div[3]/div/button[1]')
shurukuang_locator = (By.CSS_SELECTOR,'body > div.container > div.row-fluid > div > form > table > tbody > tr:nth-child(7) > td:nth-child(2) > div > div.ke-edit > iframe')

# 执行
driver.find_element(*username_locator).send_keys(username)
driver.find_element(*password_locator).send_keys(password)
driver.find_element(*dl_locator).click()
driver.find_element(*jiarenwu_locator).click()
driver.find_element(*zhuti_locator).send_keys('来任务了')

driver.find_element(*fzr_locator).click()
driver.find_element(*xzfzr_locator).click()

driver.find_element(*dianjiok_locator).click()


sleep(2)
driver.find_element(*xzxg_locator).click()
sleep(2)
driver.find_element(*xzlxr_locator).click()
sleep(3)
driver.find_element(*srnr_locator).click()
driver.find_element(*gx_locator).click()
sleep(3)
driver.find_element(*dianji_locator).click()
driver.find_element(*shurukuang_locator).send_keys('请我吃饭')
# driver.find_element(*xiangguanren).click()
# driver.find_element(*quanbuxuanhe).click()
# driver.find_element(*dianji_ok1)
sleep(2)
driver.find_element(*baocun_locator).click()

sleep(5)
driver.quit()
